<template>
  <div>
    <Dialog title="顾客退货" :loading="loading" :visible="visible" class="setUp two-columns" :reveal="true" @close="handleClose" @confirm="balanceSubmit">
      <el-row>
        <el-col :span="6">退货单号：{{ currentRow.dataCode }}</el-col>
        <el-col :span="6">来源：{{ currentRow.source }}</el-col>
        <el-col :span="6">退单人：{{ currentRow.orderMan }}</el-col>
        <el-col :span="6">顾客：{{ currentRow.customerName }}</el-col>
      </el-row>
      <div style="margin-top: 18px">
        <el-table :data="currentRow.purchaseOrderDtoList" border :row-class-name="tableColor">
          <el-table-column label="名称" prop="name" show-overflow-tooltip />
          <el-table-column label="类型" prop="type" show-overflow-tooltip />
          <el-table-column label="规格" prop="spec" show-overflow-tooltip />
          <el-table-column label="单位" prop="unit" show-overflow-tooltip />
          <el-table-column label="应退数量" prop="purchaseCount" show-overflow-tooltip />
          <el-table-column label="退货数量" prop="returnCount" min-width="140">
            <template slot-scope="{row}">
              <el-input-number v-model="row.returnCount" controls-position="right" :min="1" :max="Number(row.purchaseCount)" style="width: 120px;" />
            </template>
          </el-table-column>
        </el-table>
      </div>
      <el-row style="margin-top:20px">
        <el-col :span="6">仓库：{{ currentRow.warehouseName }}</el-col>
        <el-col :span="6" :offset="12" style="text-align:right"><el-checkbox v-model="currentRow.isStock" style="margin-right: 5px" />同时入库</el-col>
      </el-row>
    </Dialog>
  </div>
</template>

<script>
// import { mapMutations } from 'vuex';
import Dialog from "@/components/Dialog";
import { tableColor } from '@/utils/common.js';
export default {
  name: "Index",
  components: {
    Dialog,
  },
  props: {
    visible: {
      type: Boolean,
      default: false,
    },
    currentRow: {
      type: Object,
      default: () => {},
    },
    isDetails: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      loading: false,
      checked: false,
      tableColor,
    };
  },
  methods: {
    async balanceSubmit() {
      const currentRow = JSON.parse(JSON.stringify(this.currentRow));
      if (!currentRow.isStock) currentRow.isStock = false;
      this.loading = true;
      const res = await this.$api['warehouse/returnGoods/salesReturn']({ ...currentRow });
      this.loading = false;
      if (res.code !== 200) return this.$message.error(res.msg);
      this.$message.success("退货成功");
      this.$emit("successHandle");
    },
    handleClose() {
      this.$emit('handleClose');
    },
  },
};
</script>

<style scoped lang='scss'>
/deep/.el-table .cell{
  line-height: 30px !important;
}
</style>
